//
//  JXNavViewController.swift
//  weibo
//
//  Created by admin on 16/5/20.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class JXNavViewController: UINavigationController, UIGestureRecognizerDelegate {

	override func viewDidLoad() {
		super.viewDidLoad()
        //解决自定义返回按钮后不能手势返回的问题
		self.interactivePopGestureRecognizer?.delegate = self

//        navigationBar.setBackgroundImage(<#T##backgroundImage: UIImage?##UIImage?#>, forBarMetrics: <#T##UIBarMetrics#>)
	}

	override func didReceiveMemoryWarning() {
		super.didReceiveMemoryWarning()
		// Dispose of any resources that can be recreated.
	}

	//代理方法
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        return childViewControllers.count > 1
        
    }

    //设置根控制器时,会默认调用push方法,压栈
    //重写push方法
    
    override func pushViewController(viewController:
        UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            var title = "返回"
            if childViewControllers.count == 1 {
                title = (childViewControllers.first?.title)! ?? "返回"
            }
            let backBtnItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action:#selector(pop))
            
            viewController.navigationItem.leftBarButtonItem = backBtnItem
            
        }
        super.pushViewController(viewController, animated: animated)
        
    }
    
    @objc private func pop(){
        
        popViewControllerAnimated(true)
        
    }

}
